package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务表 前端控制器
 * </p>
 *
 * @author yiWen
 * @since 2025-01-16
 */
@RestController
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {
    @Autowired
    private IServeService serveService;

    @ApiOperation("区域服务分页查询")
    @GetMapping("/page")
    public PageResult<ServeResDTO> pageList(ServePageQueryReqDTO dto) {

        return serveService.pageList(dto);

    }

    @ApiOperation("添加服务")
    @PostMapping("/batch")
    public void add(@RequestBody List<ServeUpsertReqDTO> dtos) {
        serveService.batchAdd(dtos);
    }

    @PutMapping("/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
            , @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)

    })
    public void update(@PathVariable("id") Long id, @RequestParam("price") BigDecimal price) {
        serveService.updatePrice(id, price);
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("上架服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)

    })
    public void onsale(@PathVariable("id") Long id) {
        serveService.onsale(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("下架服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)

    })
    public void offsale(@PathVariable("id") Long id) {
        serveService.offsale(id);
    }
    @PutMapping("/onHot/{id}")
    @ApiOperation("上热门服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)

    })
    public void onHot(@PathVariable("id") Long id) {
        serveService.onHot(id);
    }
    @PutMapping("/offHot/{id}")
    @ApiOperation("下热门服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)

    })
    public void offHot(@PathVariable("id") Long id) {
        serveService.offHot(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除服务")
    public void delete(@NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        serveService.deleteById(id);
    }

}
